gp()
{
  echo "Pushing tags and branches"
  git push origin --all
  git push origin --tags
}

vimr()
{
  URL=$1
  SUFFIX=$(basename $URL)
  SHA=`echo $URL | shasum`
  FILENAME=${SHA//[[:blank:]]/}.$SUFFIX
  DOWNLOAD_PATH=/tmp/$FILENAME
  
  echo "Will open remote $FILENAME in vim"

  if [ ! -f $DOWNLOAD_PATH ]; then
    wget "$URL" -O "$DOWNLOAD_PATH"
  fi

  vim $DOWNLOAD_PATH
}

gicp() {
  GITHUB_USER=$(basename `pwd`)
  GITHUB_PROJECT=$1

  echo "Will clone $GITHUB_PROJECT for $GITHUB_USER" 

  if [ ! -d "$GITHUB_PROJECT" ]; then
    echo Cloning $GITHUB_PROJECT
    git clone https://github.com/$GITHUB_USER/$GITHUB_PROJECT
  else
    echo There seems to already be directory named $GITHUB_PROJECT
    echo Updating instead.
    cd $GITHUB_PROJECT
    git pull
    cd ..
  fi
}

note() {
  D=`date +"%A, %d. %B %Y"`
  NOTE_DIR=$HOME/Notes/
  NOTE=$NOTE_DIR/"$D.md"

  echo "Write your note, end by CTRL-{D,C}"
  echo "The note can be found in $NOTE_DIR"

  mkdir -p $NOTE_DIR

  if [ ! -f "$NOTE" ];
  then
    echo Date: $D >> "${NOTE}"
  fi

  echo >> "${NOTE}"
  cat >> "${NOTE}"
}

_ymp3() {
  youtube-dl --extract-audio --audio-format mp3 $1
}

_refreshk() {
  myid=756753E5
  echo "Refreshing $myid"
  gpg --keyserver pool.sks-keyservers.net --send-key $myid
  gpg --refresh-key $myid
}

_href() {
  lynx -dump -listonly
}

# Source Start { http://www.commandlinefu.com/
_fetchMissingKeys() {
  echo "Fetching any missing keys for $myid"
  for i in `gpg --list-sigs | perl -ne 'if(/User ID not found/){s/^.+([a-fA-F0-9]{8}).*/\1/; print}' | sort | uniq`; do gpg --keyserver-options no-auto-key-retrieve --recv-keys $i; done
}
# } Source End

orgclone() {
  mkdir -p $1
  cd $1
  curl -s https://api.github.com/orgs/$1/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
  cd -
}

cpa() {
  echo "Commits by authors"
  git shortlog -s -n
}

tempfileswift() {
  tempfile=$(echo "`date`" | shasum | cut -c-6).swift
  touch /tmp/$tempfile
  echo "$tempfile created in /tmp"
}

transfer() {
  curl --upload-file $1 https://transfer.sh/
}

tohtml() {
  vim +TOhtml +wqall "$1"
  open "$1".html
}

get_patch_work() {
  patch_url="https://patchwork.kernel.org/patch/$1/raw/"
  local_path="`echo $1|shasum|tr -d ' '`".patch
  echo "Using patch from $patch_url"
  wget  $patch_url -O  $local_path

  echo "Patch stored at $local_path"
  echo "You can easily apply it via: git am < $local_path"
  # TODO: ask to apply it
}

dev() {
  vim +NERDTree +Tagbar
}
